#!/bin/bash

##docker network create --driver bridge --subnet 172.18.0.0/24 --gateway 172.18.0.1 mynet


##版本 4.4.15===========================
##docker pull mongo:4.4.15
##docker run -itd --name mongo -p 27017:27017 mongo:4.4.15 --auth
##db.createUser({ user:'admin',pwd:'123456',roles:[ { role:'userAdminAnyDatabase', db: 'admin'},"readWriteAnyDatabase"]});
##db.auth('admin', '123456')


#docker exec -it mongo mongo mongodb://admin:123456@127.0.0.1:27017/?authSource=admin
#docker exec -it mongo mongo mongodb://admin@127.0.0.1:27017/?authSource=admin
#docker exec -it mongo mongo mongodb://admin@127.0.0.1:27017/test?authSource=admin


##版本 3.2.21===========================
docker pull mongo:3.2.21

docker run -itd --name mongo -p 27017:27017 mongo:3.2.21 --auth

docker exec -it mongo mongo admin



##db.createUser({ user:'admin',pwd:'QPayU7@A+s#WW',roles:[ { role:'userAdminAnyDatabase', db: 'admin'},"readWriteAnyDatabase"]});
##db.auth('admin', 'QPayU7@A+s#WW')
#docker exec -it mongo mongo mongodb://admin:QPayU7%40A%2Bs%23WW@127.0.0.1:27017/
#docker exec -it mongo mongo --host 127.0.0.1:27017 -u admin -p --authenticationDatabase admin


#db.users.find().pretty();
# db.users.find()
#var numberOfRows=db.users.count();
#print ("Number Of Rows="+numberOfRows);

